package today.rocky.boot.mongo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import today.rocky.boot.mongo.pojo.Book;
import today.rocky.boot.mongo.service.BookService;

import java.util.List;

/**
 * @version 1.0
 * @vlog:
 * @description:
 * @author: Rocky
 * @createDate: 2020/6/9 20:29
 */
@RestController
@RequestMapping("/mongo")
public class CrudController {
	@Autowired
	private BookService bookService;

	@PostMapping("/add")
	public String addBook(@RequestBody Book book){
		bookService.addBook(book);
		return "success";
	}

	@PostMapping("/upd")
	public String updateBook(@RequestBody Book book){
		bookService.updateBook(book);
		return "success";
	}

	@PostMapping("/del/{id}")
	public String deleteBook(@PathVariable("id") String id){
		bookService.deleteBookById(id);
		return "success";
	}

	@GetMapping("/find")
	public List<Book> findByLike(String name){
		return bookService.findByLike(name);
	}

	@GetMapping("/findAll")
	public List<Book>  findAll(){
		return bookService.findAll();
	}

	@GetMapping("/findId/{id}")
	public Book findBookId(@PathVariable("id") String id){
		return	bookService.findById(id);
	}

	@GetMapping("/findName")
	public Book findBookName(String name){
		return	bookService.findByName(name);
	}



}
